package com.app.micaihu.view.main.topic.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextPaint;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.app.micaihu.R;
import com.app.micaihu.app.AppApplication;
import com.app.micaihu.base.AppBaseAdapter;
import com.app.micaihu.bean.comment.NormalComment;
import com.app.micaihu.bean.speak.IAttUser;
import com.app.micaihu.bean.topic.PostItemBean;
import com.app.micaihu.configure.ActivityRequestCode;
import com.app.micaihu.configure.Config;
import com.app.micaihu.configure.TypeConstant;
import com.app.micaihu.configure.UmEventId;
import com.app.micaihu.custom.view.AttentionView;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.micaihu.listener.AutoWidthControllerListener;
import com.app.micaihu.utils.CommentUtils1;
import com.app.micaihu.utils.ImageLoadUtils;
import com.app.micaihu.utils.InteractiveUtils;
import com.app.micaihu.utils.MobclickAgentUtils;
import com.app.micaihu.view.army.activity.ArmyDetailActivity;
import com.app.micaihu.view.army.activity.ArmyMedalListActivity;
import com.app.micaihu.view.comment.SubmitCommentListener;
import com.app.micaihu.view.main.topic.PostDetailActivity;
import com.app.micaihu.view.newsdetail.ImageShowActivity;
import com.app.micaihu.view.user.userinfo.activity.MyHomepageDynamicActivity;
import com.app.utils.util.StringUtils;
import com.app.utils.util.ViewSizeUtils;
import com.app.utils.util.image.LoadImageUtils;
import com.app.utils.util.view.DrawableLeftTextCenterTextView;
import com.app.utils.util.view.expression.view.BiaoQinTextView;
import com.baidu.mobstat.StatService;
import com.blankj.utilcode.util.ActivityUtils;

import java.util.ArrayList;
import java.util.List;

import de.greenrobot.event.EventBus;


/**
 * Created by Guo on 2016/12/30.
 */

public class PostItemAdapter extends AppBaseAdapter<PostItemBean> implements View.OnClickListener {
    private int thumbSize = 140;//默认的 防止异常

    private final int NORMAL_POST = 1;//正常帖子类型
    private final int GONE_POST = 0;//隐藏掉
    private final int FLUSH = 2;//刷新

    private PostItemBean currentPostBean;//当前点击的item
    private boolean isDetail;
    private SubmitCommentListener commentListener;
    private String indexType;//排序规则 1最新 2最热

    public PostItemAdapter(List<PostItemBean> list, Context context, boolean isDetail, String indexType) {
        super(list, context);
        this.indexType = indexType;
        this.isDetail = isDetail;
//        this.thumbSize = (int) ViewSizeUtils.changeView30Per(context, 7.5f, 29f);
        this.thumbSize = (int) ViewSizeUtils.changeView30Per(context, 3.0f, 30f);
    }


    @Override
    public int getViewTypeCount() {
        return 3;
    }

    @Override
    public int getItemViewType(int position) {
//        if ("1".equals(indexType)) {
//            StatService.onEvent(context, "post_exposed", "推荐", 1);//
//            MobclickAgentUtils.event(Config.EventBauduId.post_exposed, "推荐");
//        } else {
//            StatService.onEvent(context, "post_exposed", "精华", 1);//
//            MobclickAgentUtils.event(Config.EventBauduId.post_exposed, "精华");
//        }

        PostItemBean postItemBean = list.get(position);
        if (postItemBean == null) {
            return GONE_POST;
        }
        if (InteractiveUtils.getInstance().theDefriendIsContains(postItemBean.getUid())) {
            return GONE_POST;
        }

        switch (postItemBean.getCtype()) {
            case TypeConstant.NORMAL_POST://正常帖子
                return NORMAL_POST;
            case TypeConstant.FLUSH://刷新
                return FLUSH;
            default:
                return GONE_POST;
        }

    }


    @Override
    public View creatView(int position, View convertView, ViewGroup parent) {
        PostItemBean postItemBean = list.get(position);
        MobclickAgentUtils.event(UmEventId.topiclist_exposed, "话题");
        int itemViewType = getItemViewType(position);
        if (convertView == null) {
            switch (itemViewType) {
                case NORMAL_POST:
                    convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post, null);
                    ViewHolder viewHolder = new ViewHolder(convertView);
                    convertView.setTag(viewHolder);
                    setNormalPostData(convertView, viewHolder, postItemBean);

                    break;
                case GONE_POST:
                    convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout_gone, null);
                    GoneViewHolder goneViewHolder = new GoneViewHolder();
                    convertView.setTag(goneViewHolder);
                    break;
                case FLUSH:
                    convertView = inflater.inflate(R.layout.item_newslist_flush, null);
                    break;
            }
        } else {
            switch (itemViewType) {
                case NORMAL_POST:
                    ViewHolder viewHolder = (ViewHolder) convertView.getTag();
                    setNormalPostData(convertView, viewHolder, postItemBean);
                    break;
                case GONE_POST:
                    break;
                case FLUSH:
                    break;
            }
        }


        return convertView;
    }


    /**
     * 当前页面关注后刷新
     */
    private AttentionView.SucessListener sucessListener = new AttentionView.SucessListener() {
        @Override
        public void changeView(IAttUser iAttUser) {
            if (iAttUser != null) {
                Bundle bundle = new Bundle();
                bundle.putInt("type", 1);
                bundle.putString(Config.Extra.PARAMETER1, iAttUser.getIAttType());
                bundle.putString(Config.Extra.PARAMETER2, iAttUser.getIToUid());
                EventBus.getDefault().post(bundle);

            }

        }
    };

    private void setNormalPostData(View convertView, ViewHolder viewHolder, PostItemBean postItemBean) {
        convertView.setVisibility(View.VISIBLE);
        viewHolder.attentionView.setTag(postItemBean);
        viewHolder.attentionView.setEventValue("话题");
        viewHolder.attentionView.setSucessListener(sucessListener);


//        LoadImageUtils.getInstance().loadCircleImage(viewHolder.civHeadpic, postBean.getHeadPic());


        LoadImageUtils.getInstance().loadListCircleImage(viewHolder.civHeadpic, postItemBean.getHeadPic());
        viewHolder.tvNickname.setText(postItemBean.getNickName());
        viewHolder.tvPublishtime.setText(postItemBean.getPublishTime());
        showBtomView(viewHolder, postItemBean.getReplyNum(), postItemBean.getPraiseNum());
        //判断是否点赞过
        if (InteractiveUtils.getInstance().theLaudIsContains(postItemBean.getId(), true) && StringUtils.toInt(postItemBean.getPraiseNum(), 0) > 0) {
            viewHolder.tvGood.setEnabled(false);
            viewHolder.flLaud.setTag(true);
        } else {
            viewHolder.tvGood.setEnabled(true);
            viewHolder.flLaud.setTag(postItemBean);
        }
        //设置可点击的帖子内容，在详情中不可点击，在推荐中点击
//        setClickableName(viewHolder, postBean);
        if (!TextUtils.isEmpty(postItemBean.getContent())) {
            viewHolder.tvPostcontent.setVisibility(View.VISIBLE);
            viewHolder.tvPostcontent.setPicText(postItemBean.getContent());

        } else {
            viewHolder.tvPostcontent.setVisibility(View.GONE);

        }


        float measureText = viewHolder.paint.measureText(postItemBean.getContent());
//        LogUtils.e("gzq", "width = "+width + "    measureText = "+measureText + "   ViewSizeUtils.getWidthPixels() = "+ViewSizeUtils.getWidthPixels());
        if (measureText > ViewSizeUtils.getWidthPixels() * 5) {
            viewHolder.tvAllcontent.setVisibility(View.VISIBLE);

        } else {
            viewHolder.tvAllcontent.setVisibility(View.GONE);
        }


        if (viewHolder.tvPostcontent.getVisibility() == View.GONE) {
            viewHolder.tvAllcontent.setVisibility(View.GONE);
        }


        //设置帖子的缩略图
        List<String> imgList = postItemBean.getImgList();
        setPostThumb(viewHolder, imgList);


        //2.0.1.4新增字段填充数据
        LoadImageUtils.getInstance().loadImage(viewHolder.civRank, postItemBean.getRankIcon());
        if (com.blankj.utilcode.util.StringUtils.isEmpty(postItemBean.getHonourPic())) {
            viewHolder.ivHonourPic.setVisibility(View.GONE);
        } else {
            viewHolder.ivHonourPic.setVisibility(View.VISIBLE);
            ImageLoadUtils.loadImage(postItemBean.getHonourPic(), viewHolder.ivHonourPic);
        }
        viewHolder.tvRankName.setText(postItemBean.getRankName());
        viewHolder.tvArmyGroupInfo.setText(postItemBean.getArmyGroupInfo());
        if (TextUtils.isEmpty(postItemBean.getTitle())) {
            viewHolder.tvPostTitle.setVisibility(View.GONE);
        } else {
            viewHolder.tvPostTitle.setVisibility(View.VISIBLE);
            viewHolder.tvPostTitle.setText(postItemBean.getTitle());
        }

        //设置个人主页的跳转
        viewHolder.tvNickname.setTag(postItemBean);
        viewHolder.civHeadpic.setTag(postItemBean);

        viewHolder.flComment.setTag(postItemBean);
        viewHolder.flComment.setTag(R.id.tag_first, postItemBean);
        viewHolder.tvAllcontent.setTag(R.id.tag_first, postItemBean);
        viewHolder.llContainer.setTag(R.id.tag_first, postItemBean);
        convertView.setTag(R.id.tag_first, postItemBean);
        viewHolder.tvPostTitle.setTag(R.id.tag_first, postItemBean);

        viewHolder.ivHonourPic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!com.blankj.utilcode.util.StringUtils.isEmpty(postItemBean.getUid())) {
                    Intent intent = new Intent(context, ArmyMedalListActivity.class);
                    intent.putExtra(Config.Extra.toUid, postItemBean.getUid());
                    ActivityUtils.startActivity(intent);
                }

            }
        });
        viewHolder.tvArmyGroupInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!com.blankj.utilcode.util.StringUtils.isEmpty(postItemBean.getUid()) && !com.blankj.utilcode.util.StringUtils.isEmpty(postItemBean.getGid())) {
                    Intent intent = new Intent(context, ArmyDetailActivity.class);
                    intent.putExtra(Config.Extra.toUid, postItemBean.getUid());
                    intent.putExtra(Config.Extra.id, postItemBean.getGid());
                    ActivityUtils.startActivity(intent);
                }
            }
        });

    }

    private void setPostThumb(ViewHolder viewHolder, List<String> imgList) {
        if (imgList == null || imgList.size() <= 0) {
            viewHolder.flAllImgContainer.setVisibility(View.GONE);
        } else {
            viewHolder.flAllImgContainer.setVisibility(View.VISIBLE);
            if (imgList.size() == 1) {
                viewHolder.civThumbBig.setVisibility(View.VISIBLE);
                viewHolder.llImgContainer3.setVisibility(View.GONE);
                LoadImageUtils.getInstance().loadImage(viewHolder.civThumbBig, imgList.get(0), viewHolder.autoWidthControllerListener);
            } else {
                viewHolder.civThumbBig.setVisibility(View.GONE);
                viewHolder.llImgContainer3.setVisibility(View.VISIBLE);
                viewHolder.civThumb0.setVisibility(View.VISIBLE);
                LoadImageUtils.getInstance().loadImage(viewHolder.civThumb0, imgList.get(0));

                viewHolder.civThumb1.setVisibility(View.VISIBLE);
                LoadImageUtils.getInstance().loadImage(viewHolder.civThumb1, imgList.get(1));
                if (imgList.size() > 2) {
                    viewHolder.civThumb2.setVisibility(View.VISIBLE);
                    LoadImageUtils.getInstance().loadImage(viewHolder.civThumb2, imgList.get(2));
                } else {
                    viewHolder.civThumb2.setVisibility(View.GONE);
                }
            }


            if (imgList.size() > 3) {
                viewHolder.tvNum.setText(imgList.size() + "图");
                viewHolder.tvNum.setVisibility(View.VISIBLE);
            } else {
                viewHolder.tvNum.setVisibility(View.GONE);
            }
            //为图片设置tag
            viewHolder.civThumb0.setTag(imgList);
            viewHolder.civThumb1.setTag(imgList);
            viewHolder.civThumb2.setTag(imgList);
            viewHolder.civThumbBig.setTag(imgList);
        }

    }

    private void showBtomView(ViewHolder viewHolder, String replyNum, String praiseNum) {
        if (TextUtils.isEmpty(replyNum) || TextUtils.equals("0", replyNum)) {
            viewHolder.tvCommentnum.setText(AppApplication.getInstance().getString(R.string.comment));
        } else {
            viewHolder.tvCommentnum.setText(replyNum);
        }
        if (TextUtils.isEmpty(praiseNum) || TextUtils.equals("0", praiseNum)) {
            viewHolder.tvGood.setText(AppApplication.getInstance().getString(R.string.common_zan));
        } else {
            viewHolder.tvGood.setText(praiseNum);
        }

    }

    @Override
    public void onClick(View v) {
        if (v == null) return;
        switch (v.getId()) {
            case R.id.civ_headpic://点击->进个人主页
            case R.id.tv_nickname:
                //进入个人主页
                try {
                    currentPostBean = (PostItemBean) v.getTag();
                    if (currentPostBean != null) {
//                        InteractiveUtils.getInstance().goToUserHome((Activity)context,currentPostBean.getUid());
                        MyHomepageDynamicActivity.goToUserHomePage((Activity) context, currentPostBean.getUid());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

                break;
            case R.id.civ_big_thumb:
            case R.id.civ_thumb0:
                if (v.getTag() instanceof List) {
                    ArrayList imgList = (ArrayList) v.getTag();
                    showImageDetail(imgList, 0);
                }

                break;
            case R.id.civ_thumb1:
                if (v.getTag() instanceof List) {
                    ArrayList imgList = (ArrayList) v.getTag();
                    showImageDetail(imgList, 1);
                }

                break;
            case R.id.civ_thumb2:
                if (v.getTag() instanceof List) {
                    ArrayList imgList = (ArrayList) v.getTag();
                    showImageDetail(imgList, 2);
                }

                break;

            case R.id.ll_item_post://进入帖子详情
            case R.id.tv_allcontent:
            case R.id.tv_posttitle:
                if ("1".equals(indexType)) {
                    StatService.onEvent(context, "post_click", "推荐", 1);// 统计的点击的次数
                    MobclickAgentUtils.event(Config.EventBauduId.post_click, "推荐");
                } else {
                    StatService.onEvent(context, "post_click", "精华", 1);// 统计的点击的次数
                    MobclickAgentUtils.event(Config.EventBauduId.post_click, "精华");
                }

                goToPostDetail(v, false);
                break;
            case R.id.fl_laud://点击->点赞
                InteractiveUtils.getInstance().laud((FrameLayout) v, null);

                break;

            case R.id.fl_comment://点击评论 数 ,进入帖子
                if ("1".equals(indexType)) {
                    StatService.onEvent(context, Config.EventBauduId.post_comment, "推荐", 1);// 统计的点击的次数
                    MobclickAgentUtils.event(Config.EventBauduId.post_comment, "推荐");
                } else {
                    StatService.onEvent(context, Config.EventBauduId.post_comment, "精华", 1);// 统计的点击的次数
                    MobclickAgentUtils.event(Config.EventBauduId.post_comment, "精华");
                }
                goToPostDetail(v, true);
//                if(v.getTag() != null && v.getTag() instanceof PostItemBean){
//                    currentPostBean = (PostItemBean) v.getTag();
//                }
//
//                replyPost();
                break;

//            case R.id.tv_posttitle:
//                //去往当前话题
//
//                break;
        }

    }

    private void replyPost() {
        if (currentPostBean == null) return;
        if (commentListener == null) {
            commentListener = new SubmitCommentListener() {
                @Override
                public void startSubmit() {

                }

                @Override
                public void errorSubmit(VolleyError error) {

                }

                @Override
                public void successSubmit(NormalComment normalComment) {
                    currentPostBean.setReplyNum((StringUtils.toInt(currentPostBean.getReplyNum(), 0) + 1) + "");
                    notifyDataSetChanged();
                }
            };
        }


        CommentUtils1.getInstance().showDialog((Activity) context, "",
                currentPostBean.getNewsId(), currentPostBean, commentListener, false, false);
    }


    public void notifyZanComment(int zanNum, int commentNum, boolean isDelete) {
        if (currentPostBean != null) {
            if (isDelete) {
                list.remove(currentPostBean);
            } else {
//                if (zanNum != 0) {
                currentPostBean.setPraiseNum(zanNum + "");
//                }
//                if (commentNum != 0) {
                currentPostBean.setReplyNum(commentNum + "");
//                }
            }

            notifyDataSetChanged();
        }
    }

    /**
     * 展示大图
     *
     * @param imgList
     * @param i
     */
    private void showImageDetail(ArrayList imgList, int i) {
        Intent intent = new Intent(context, ImageShowActivity.class);
        intent.putStringArrayListExtra(Config.Extra.PARAMETER1, imgList);
        intent.putExtra(Config.Extra.PARAMETER2, i);
        intent.setClass(context, ImageShowActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (context instanceof Activity) {
            context.startActivity(intent);
            ((Activity) context).overridePendingTransition(R.anim.base_alpha_in, R.anim.base_slide_remain);// 前一个参数是下一个Activity的效果
        }
    }


    /**
     * 进入帖子详情
     *
     * @param v
     */
    private void goToPostDetail(View v, boolean seeComment) {
        MobclickAgentUtils.event(UmEventId.topiclist_click, "话题");
        if (v.getTag(R.id.tag_first) != null && v.getTag(R.id.tag_first) instanceof PostItemBean) {
            this.currentPostBean = (PostItemBean) v.getTag(R.id.tag_first);
            String postId = currentPostBean.getId();
            Intent intent = new Intent();
            intent.putExtra(Config.Extra.PARAMETER1, postId);
            intent.putExtra(Config.Extra.indexType, indexType);
            if (seeComment) {
                intent.putExtra("seeComment", true);
            }

            intent.putExtra(PostDetailActivity.COMMENT_SUM, this.currentPostBean.getReplyNum());
            intent.putExtra(PostDetailActivity.PARISE_SUM, this.currentPostBean.getPraiseNum());
            intent.putExtra(Config.Extra.eventValue, "话题");

            intent.setClass(context, PostDetailActivity.class);
            ((Activity) context).startActivityForResult(intent, ActivityRequestCode.REQUEST_CODE_TOPIC_DETAIL);
            ((Activity) context).overridePendingTransition(R.anim.base_slide_right_in, R.anim.base_slide_remain);
        }
    }

    class ViewHolder {
        LinearLayout llContainer;
        CustomImageView civHeadpic;
        TextView tvNickname;
        TextView tvPublishtime;
        BiaoQinTextView tvPostcontent;
        TextView tvAllcontent;

        FrameLayout flAllImgContainer;
        LinearLayout llImgContainer3;
        CustomImageView civThumb0;
        CustomImageView civThumb1;
        CustomImageView civThumb2;
        CustomImageView civThumbBig;

        DrawableLeftTextCenterTextView tvCommentnum;
        DrawableLeftTextCenterTextView tvGood;

        AutoWidthControllerListener autoWidthControllerListener;
        AutoWidthControllerListener.OnLoadCompeleted onLoadCompeleted;
        //2.0.1.4新增字段
        TextView tvPostTitle;//话题的title
        TextView tvRankName;//发帖人的军衔名称
        TextView tvArmyGroupInfo;//发帖人的军衔名称
        AttentionView attentionView;//关注按钮
        CustomImageView civRank;//军衔
        CustomImageView ivHonourPic;//军衔

        FrameLayout.LayoutParams param;

        //204 点赞
        FrameLayout flComment;
        FrameLayout flLaud;


        TextView tvNum;
        TextPaint paint;

        ViewHolder(View convertView) {
            llContainer = (LinearLayout) convertView.findViewById(R.id.ll_item_post);
            civHeadpic = (CustomImageView) convertView.findViewById(R.id.civ_headpic);
            tvNickname = (TextView) convertView.findViewById(R.id.tv_nickname);
            tvPublishtime = (TextView) convertView.findViewById(R.id.tv_publishtime);
            tvPostcontent = (BiaoQinTextView) convertView.findViewById(R.id.tv_postcontent);
            tvAllcontent = (TextView) convertView.findViewById(R.id.tv_allcontent);
            tvArmyGroupInfo = (TextView) convertView.findViewById(R.id.tvArmyGroupInfo);

            flAllImgContainer = (FrameLayout) convertView.findViewById(R.id.fl_imagecontainer);

            llImgContainer3 = (LinearLayout) convertView.findViewById(R.id.ll_image_container3);
            civThumb0 = (CustomImageView) convertView.findViewById(R.id.civ_thumb0);
            civThumb1 = (CustomImageView) convertView.findViewById(R.id.civ_thumb1);
            civThumb2 = (CustomImageView) convertView.findViewById(R.id.civ_thumb2);

            ViewSizeUtils.changeViewWH(civThumb0, thumbSize, thumbSize);
            ViewSizeUtils.changeViewWH(civThumb1, thumbSize, thumbSize);
            ViewSizeUtils.changeViewWH(civThumb2, thumbSize, thumbSize);


            civThumbBig = (CustomImageView) convertView.findViewById(R.id.civ_big_thumb);

            tvNum = (TextView) convertView.findViewById(R.id.tv_num);


            tvCommentnum = (DrawableLeftTextCenterTextView) convertView.findViewById(R.id.tv_commentnum);
            tvGood = (DrawableLeftTextCenterTextView) convertView.findViewById(R.id.tv_good);
            flComment = (FrameLayout) convertView.findViewById(R.id.fl_comment);
            flLaud = (FrameLayout) convertView.findViewById(R.id.fl_laud);

            param = (FrameLayout.LayoutParams) tvCommentnum.getLayoutParams();
            param.width = ViewSizeUtils.getWidthPixels() / 2;
            tvCommentnum.setLayoutParams(param);
            tvGood.setLayoutParams(param);

            flComment.setOnClickListener(PostItemAdapter.this);
            flLaud.setOnClickListener(PostItemAdapter.this);


//            ViewTreeObserver viewTreeObserver = tvPostcontent.getViewTreeObserver();
//            viewTreeObserver.addOnPreDrawListener(this);

            //头像-点击事件
            civHeadpic.setOnClickListener(PostItemAdapter.this);
            tvNickname.setOnClickListener(PostItemAdapter.this);

            //缩略图的点击事件
            //flAllImgContainer.setOnClickListener(TopicPostAdapter.this);
            civThumbBig.setOnClickListener(PostItemAdapter.this);
            civThumb0.setOnClickListener(PostItemAdapter.this);
            civThumb1.setOnClickListener(PostItemAdapter.this);
            civThumb2.setOnClickListener(PostItemAdapter.this);

//            tvCommentnum.setOnClickListener(PostItemAdapterOld.this);
            tvAllcontent.setOnClickListener(PostItemAdapter.this);
            convertView.setOnClickListener(PostItemAdapter.this);

            //设置监听
            autoWidthControllerListener = new AutoWidthControllerListener(civThumbBig);


            tvPostTitle = (TextView) convertView.findViewById(R.id.tv_posttitle);
            tvRankName = (TextView) convertView.findViewById(R.id.tv_rankname);
            attentionView = (AttentionView) convertView.findViewById(R.id.tv_attention);
            civRank = (CustomImageView) convertView.findViewById(R.id.civ_rank);
            ivHonourPic = (CustomImageView) convertView.findViewById(R.id.ivHonourPic);
            tvPostTitle.setOnClickListener(PostItemAdapter.this);

            onLoadCompeleted = new AutoWidthControllerListener.OnLoadCompeleted() {
                @Override
                public void onLoadCompeleted(CustomImageView civ, boolean flag) {
                    if (flag) {
                        tvNum.setVisibility(View.VISIBLE);
                        tvNum.setText(AppApplication.getInstance().getString(R.string.longpic));
                    } else {
                        tvNum.setVisibility(View.GONE);
                    }

                }
            };
            autoWidthControllerListener.setOnLoadCompeleted(onLoadCompeleted);


            paint = tvPostcontent.getPaint();
//            if (isDetail) {
//                tvPostTitle.setVisibility(View.GONE);
//            } else {
//                tvPostTitle.setVisibility(View.VISIBLE);
//            }
        }


//        @Override
//        public boolean onPreDraw() {

//            int width = tvPostcontent.getWidth();
//            TextPaint paint = tvPostcontent.getPaint();
//            float measureText = paint.measureText(tvPostcontent.getText().toString());
//            if (measureText > width * 5) {
//                tvAllcontent.setVisibility(View.VISIBLE);
//
//            } else {
//                tvAllcontent.setVisibility(View.GONE);
//            }
//            if (tvPostcontent.getVisibility() == View.GONE){
//                tvAllcontent.setVisibility(View.GONE);
//            }

//            return true;
//        }
    }


    class GoneViewHolder {
        public GoneViewHolder() {
        }
    }


}
